#include "binaryprocesshelper.h"
#include "common/dataspecificationutils.h"

namespace DataSpecificationGW
{
    void parseBinaryField(QDataStream& in, const bool bSkip, const StringType eStringType, const size_t size, QString& qstrField, bool& bFieldExist)
    {
        bFieldExist = false;
        if (bSkip)
        {
            return;
        }

        switch (eStringType)
        {
        case DataSpecificationGW::TYPE_VERSION:
        {
            std::vector<quint8> vecValue;
            if (DataSpecificationUtils::getUint8Vector(in, size, vecValue))
            {
                qstrField.clear();
                for (int i = 0; i < size; ++i)
                {
                    qstrField += QString::number(vecValue[i]);
                    if (i != size - 1)
                    {
                        qstrField += '.';
                    }
                }

                bFieldExist = true;
            }
        }
            break;
        case DataSpecificationGW::TYPE_UNICODE:
            if (DataSpecificationUtils::getUnicode(in, size, qstrField))
            {
                bFieldExist = true;
            }
            break;
        case DataSpecificationGW::TYPE_ASCII:
            if (DataSpecificationUtils::getAscii(in, size, qstrField))
            {
                bFieldExist = true;
            }
            break;
        case DataSpecificationGW::TYPE_DATETIME:
        {
            qint64 lDataTime;
            in >> lDataTime;
            qstrField = QString::number(lDataTime);
        }
            break;
        default:
            break;
        }
    }

}
